﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
public partial class Ad_Admanager : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Check.CheckPermission("300400105");
        if (!this.IsPostBack)
        {
            ShowAD();
                  
        }
    }

    public void ShowAD()
    {
        this.dlistADDetail.DataSource = new BLL.Ad().GetAllList();
        this.dlistADDetail.DataBind();
    
    }
    protected void dlistOrderDetail_ItemCommand(object source, DataListCommandEventArgs e)
    {

        if (e.CommandName.ToLower() == "del")
        {
            if (!Check.CheckPermission("300400107", "00003"))
            {
                Share.Alert(this.Page, "无权操作！"); return;
            }
            Label lblbAdid = (Label)e.Item.FindControl("lbAdid");
            Model.Ad admodel = null;

                 admodel = new BLL.Ad().GetModel(lblbAdid.Text);
                if (System.IO.File.Exists(System.Web.HttpContext.Current.Server.MapPath("~/") + admodel.AdPicAddress))
                {
                    File.Delete(System.Web.HttpContext.Current.Server.MapPath("~/") +  admodel.AdPicAddress);
                }
            new BLL.Ad().Delete(lblbAdid.Text);
            ShowAD();
        }

        if (e.CommandName.ToLower() == "update")
        {
            if (!Check.CheckPermission("300400107", "00002"))
            {
                Share.Alert(this.Page,"无权操作！"); return;
            }
            Label lblbAdid = (Label)e.Item.FindControl("lbAdid");
            Response.Redirect("AddAD.aspx?adid=" +  lblbAdid.Text.Trim());
        }

        if (e.CommandName.ToLower() == "make")
        {
            if (!Check.CheckPermission("300400107", "00001"))
            {
                Share.Alert(this.Page, "无权操作！"); return;
            }
            Label lblbAdid = (Label)e.Item.FindControl("lbAdid");
            Response.Redirect("makeCode.aspx?adid=" + lblbAdid.Text.Trim());
        }



        

    }
    protected void dlistOrderDetail_ItemDataBound(object sender, DataListItemEventArgs e)
    {

    }
    protected void btnAddProduct_Click(object sender, EventArgs e)
    {
        Response.Redirect("AddAD.aspx");
    }
}
